<?php



function render_in_table($obj_array, $controller, $execpt_cols = array()) {
	if ($first_row = $obj_array[0]) {
		$column_names = get_object_vars($first_row);
		echo "<table><tr>";
		foreach ($column_names as $column_name => $val) { if (!in_array($column_name, $execpt_cols)) { echo '<th>' . ucfirst($column_name) . '</th>'; }}
		echo "</tr>";
		foreach ($obj_array as $obj) {
			foreach ($execpt_cols as $variable) { unset($obj->$variable); }
			echo "<tr>";
			foreach (get_object_vars($obj) as $attr) { echo "<td>{$attr}</td>"; }
			echo '<td>',
			link_to("Edit", array("controller" => $controller, "action" => 'edit', "id" => $obj->id)),
			'</td><td>',
			delete_link("Delete", array("controller" => $controller, "action" => 'destroy', "id" => $obj->id)),
			'</td></tr>';
		}
		echo "</table>";
	}
	else { echo "no elements to display"; }

}


function render_in_table_advanced($obj_array, $controller, $action, $execpt_cols = array()) {
	if ($first_row = $obj_array[0]) {
		$column_names = get_object_vars($first_row);
		echo '<table><tr>';
		foreach ($column_names as $column_name => $val) { if (!in_array($column_name, $execpt_cols)) { echo '<th>' . ucfirst($column_name) . '</th>'; } }
		echo '</tr>';
		foreach ($obj_array as $obj) {
			foreach ($execpt_cols as $variable) { unset($obj->$variable); }
			echo '<tr>';
			foreach (get_object_vars($obj) as $attr) { echo '<td>' . $attr . '</td>';	}
			echo '<td>',
			link_to('Edit', array('controller' => $controller, 'action' => $action, 'id' => $obj->id)),
			'</td><td>',
			delete_link('Delete', array('controller' => $controller, 'action' => $action, 'id' => $obj->id)),
			'</td></tr>';
		}
		echo '</table>';
	}
	else { echo 'no elements to display'; }
}

function render_form_for_advanced($class_name, $render_attrs = array()) {
	foreach($render_attrs as $attrs) {
		label($class_name, $attrs);
		text_field($class_name, $attrs);
		//was considering doin
		//render_form_for_advanced('product', array('name', 'description', 'datetime' => 'created_at', 'datetime' => 'updated_at', 'text' => 'watever'));
		//then doin checks for keys...just a thoguht
	}
}




/*
	$checked_playgroundequipments_ids = array();
	if (ID) {
		foreach ($this->product->playgroundequipments as $playgroundequipment_for_id) {
			array_push($checked_playgroundequipments_ids, $playgroundequipment_for_id->id);
		}
	}
	foreach ($this->all_playground_equipments as $playground_equipment) {
		check_box_tag("equipments[]", $playground_equipment->id, in_array($playground_equipment->id, $checked_playgroundequipments_ids));
		echo $playground_equipment->name;
		echo "<br />";
	}
*/
//render_check_boxes_advanced('equipments', ID, $this->product->playgroundequipments, $this->all_playground_equipments, 'name');
function render_check_boxes_advanced($export_array_name, $param_id = false, $this_has_many_items, $all_possible_has_many, $print_value) {
	$checked_ids = array();
	if ($param_id) { foreach ($this_has_many_items as $item_for_id) { array_push($checked_ids, $item_for_id->id); } }
	foreach ($all_possible_has_many as $possible_has_many_item) {
		check_box_tag($export_array_name . '[]', $possible_has_many_item->id, in_array($possible_has_many_item->id, $checked_ids));
		echo $possible_has_many_item->$print_value, '<br />';
	}
}


?>